package com.yuchen.utils;

import org.ocpsoft.prettytime.PrettyTime;
import org.ocpsoft.prettytime.units.JustNow;
import org.ocpsoft.prettytime.units.Millisecond;
import org.ocpsoft.prettytime.units.Second;

import java.util.Date;
import java.util.Locale;

/**
 *
 */
public class PrettytimeUtils {

    private final static PrettyTime PRETTY_TIME = new PrettyTime(Locale.CHINESE);

    static{
        PRETTY_TIME.removeUnit(JustNow.class);
        PRETTY_TIME.removeUnit(Second.class);
        PRETTY_TIME.removeUnit(Millisecond.class);
    }

    public static String pretty(Date date){
        return PRETTY_TIME.format(date);
    }

    public static void main(String[] args) {
        Date  date = new Date(1430185031029l);
        System.out.println(date.getTime());
        //1430185031029
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(PrettytimeUtils.pretty(date));
    }
}
